package com.zhiyu.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.zhiyu.api.ReturnMsg;
import com.zhiyu.api.ReturnResult;
import com.zhiyu.service.webApi.IScheduleTaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

@Slf4j
@Service(version = "1.0.0")
public class ScheduleTaskServiceImpl implements IScheduleTaskService {

    /**
     * 设备库存预警任务
     * @return
     */
    @Override
    @Transactional
    public ReturnResult deviceStockWarningTasks() {
        ReturnResult returnResult = ReturnResult.success();
        try {
            Map<String, Object> param = new HashMap<>();
            log.info("执行[设备库存预警]任务结束时间: "+ LocalDateTime.now());
            returnResult.setData(param);
        } catch (Exception e) {
            log.error("执行设备库存预警任务发生异常",e);
            returnResult.setCode(ReturnMsg.ERROR.getCode());
            returnResult.setMsg("执行设备库存预警任务发生异常");
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return returnResult;
        }
        return returnResult;
    }

}